<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>综合操盘 - 支付确认</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/own.css"/>
    <script type="text/javascript" src="../../js/mui.min.js"></script> 
    <script type="text/javascript" src="../../js/common.js"></script>
    <script src="../../js/jquery-1.11.3.js"></script>
    <script>
    	mui.init(); 
    	var win=null;
    	mui.plusReady(function(){
    		win=plus.webview.currentWebview();
    		//初始化监听头部和底部事件
    		var paramUrl={
				url:"../login/login.html"
			}
  			//获取支付申请数据
  			mui.app_request("/user/ftrade/apply",{
  				"traderBond":win.traderBond,
			    "tranLever":0,
				"businessType":win.businessType
  			},function(result){
  				console.log(JSON.stringify(result));
  				if(!mui.isnull(result.data)){
  					//读取详细数据
  					setconfirmInfo(result.data.confirmInfo);
  					//读取代金券
  				}
  				//比较余额是否充足
	  			compares();
  			},function(result){
  				console.log(JSON.stringify(result));
  				if(result.code==2){
  					mui.toast("申请失败");
  					return;
  				}
  			},paramUrl)
  			
  			document.getElementById("chargeto").addEventListener("tap",function(){
  				
  				var money = document.getElementById("traderBond").innerHTML;
		  			mui.openWindow({
				    url:'../account/recharge.html',
				    id:'recharge.html',
				    extras:{
				        money : money,
				       backPage:"cp.html",
				       backId:"paycp.html"
				    }
				});
	  			});
  			
  			document.getElementById("payto").addEventListener("tap",function(){
  				this.setAttribute('disabled','disabled')  //禁用按钮
  				//支付确认
  				payMoney();
  			});
  			
  			document.getElementById("back").addEventListener("tap",function(){
    			mui.back();
    		});
  			
  			document.getElementById("tran_info").addEventListener("tap",function(){
  				mui.openWindow("../agree/cpru.html");
  			});
  			
							
    	
    	
    	
    	function compareAddvoucher(){
    		var balance=document.getElementById("balance").innerHTML;
    		var traderBond=document.getElementById("traderBond").innerHTML;
    		balance=tzdr.moneyUtils.reverseMoney(balance);
    		traderBond=tzdr.moneyUtils.reverseMoney(traderBond);
    		
    		var isThrough=balance >= traderBond ? true : false;
    		
    		if(isThrough){
    			document.getElementById("pays_money").style.display="block";
    			document.getElementById("payto").style.display="block";
    			document.getElementById("pays_nomoney").style.display="none";
    			document.getElementById("chargeto").style.display="none";
    		}else{
    			document.getElementById("pays_nomoney").style.display="block";
    			document.getElementById("chargeto").style.display="block";
    			document.getElementById("pays_money").style.display="none";
    			document.getElementById("payto").style.display="none";
    		}
    		
    	}
    	
    	
    	
    	
    	function compares(){
    		var balance=document.getElementById("balance").innerHTML;
    		var traderBond=document.getElementById("traderBond").innerHTML;
    		balance=tzdr.moneyUtils.reverseMoney(balance);
    		traderBond=tzdr.moneyUtils.reverseMoney(traderBond);
    		

    		if(balance>=traderBond){
    			document.getElementById("pays_money").style.display="block";
    			document.getElementById("payto").style.display="block";
    		}else{
    			document.getElementById("pays_nomoney").style.display="block";
    			document.getElementById("chargeto").style.display="block";
    		}
    	};
    	
    	
    	function setconfirmInfo(confirmInfo){
    		document.getElementById("lineLoss").innerHTML=tzdr.moneyUtils.formatCurrency(confirmInfo.lineLoss)+"美元";
    		document.getElementById("traderTotal").innerHTML=tzdr.moneyUtils.formatCurrency(confirmInfo.traderTotal)+"美元";
    		document.getElementById("traderBond").innerHTML=tzdr.moneyUtils.formatCurrency(confirmInfo.payable)+"元";
    		document.getElementById("balance").innerHTML=tzdr.moneyUtils.formatCurrency(confirmInfo.balance)+"元";
    		setleveInfo(confirmInfo);
    	};
    	
    	//创建交易品种-手数子元素
    	
    	function setleveInfo(confirmInfo){
    		var tradelever_info=document.getElementById("tradelever_info");
    		if(!mui.isnull(confirmInfo.crudeTranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="富时A50 - "+confirmInfo.tranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="富时A50 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.crudeTranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="国际原油 - "+confirmInfo.crudeTranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="国际原油 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.hsiTranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="恒指期货 - "+confirmInfo.hsiTranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="恒指期货 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.mdtranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="迷你道指 - "+confirmInfo.mdtranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="迷你道指 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.mntranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="迷你纳指 - "+confirmInfo.mntranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="迷你纳指 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.mbtranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="迷你标普 - "+confirmInfo.mbtranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="迷你标普 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.daxtranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="德国DAX - "+confirmInfo.daxtranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="德国DAX - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.nikkeiTranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="日经225 - "+confirmInfo.nikkeiTranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="日经225 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.hstranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="小恒指 - "+confirmInfo.hstranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="小恒指 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.agtranLever)){
    			var b=document.createElement("b");
    			b.innerHTML="美黄金 - "+confirmInfo.agtranLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="美黄金 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		
    		
    		if(!mui.isnull(confirmInfo.hStockMarketLever)){
    			var b=document.createElement("b");
    			b.innerHTML="H股指数 - "+confirmInfo.hStockMarketLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="H股指数 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.xHStockMarketLever)){
    			var b=document.createElement("b");
    			b.innerHTML="小H股指数- "+confirmInfo.xHStockMarketLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="小H股指数 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.ameCopperMarketLever)){
    			var b=document.createElement("b");
    			b.innerHTML="美铜 - "+confirmInfo.ameCopperMarketLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="美铜 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.ameSilverMarketLever)){
    			var b=document.createElement("b");
    			b.innerHTML="美白银 - "+confirmInfo.ameSilverMarketLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="美白银 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.smallCrudeOilMarketLever)){
    			var b=document.createElement("b");
    			b.innerHTML="小原油 - "+confirmInfo.smallCrudeOilMarketLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="小原油 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.daxtranMinActualLever)){
    			var b=document.createElement("b");
    			b.innerHTML="迷你德国DAX指数 - "+confirmInfo.daxtranMinActualLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="迷你德国DAX指数 - 0手";
    			tradelever_info.appendChild(b);
    		}
    		if(!mui.isnull(confirmInfo.naturalGasActualLever)){
    			var b=document.createElement("b");
    			b.innerHTML="天然气指数 - "+confirmInfo.naturalGasActualLever+"手";
    			tradelever_info.appendChild(b);
    		}else{
    			var b=document.createElement("b");
    			b.innerHTML="天然气指数 - 0手";
    			tradelever_info.appendChild(b);
    		}
    	}
//  	var traderBond=document.getElementById("traderBond").innerHTML;
//  	traderBond=tzdr.moneyUtils.reverseMoney(traderBond);
//			console.log(traderBond);
    	function payMoney(){
    		var traderBond=document.getElementById("traderBond").innerHTML;
    		traderBond=tzdr.moneyUtils.reverseMoney(traderBond);
    		if(mui.isnull(traderBond)){
    			mui.toast("请选择保证金！");
    			return;
    		}
			var paramUrl={
				url:"../login/login.html"
			}
			var vid=-1;
    		mui.app_request("/user/ftrade/handle",{
    			"vid":vid,
				"traderBond":win.traderBond,
				"tranLever":0,
				"businessType":win.businessType
    		},function(result){
    			
    			var paycp=plus.webview.getWebviewById("paycp.html");
    			setTimeout(function(){
    				if(paycp){
					paycp.close();
				}
    			},1000);
    			
    			mui.openWindow({
    				url:"futurePaySuc.html",
    				id:"futurePaySuc.html",
    				extras:{
    					type:win.businessType,
    					vid:result.data.id,
    					isPay:result.data.stateType
    				}
    				});
    			return;
    		},function(result){
    			if(result.code==3){
    				mui.toast("余额不足");
    				return;
    			}else if(result.code==2){
    				mui.toast("支付确认失败");
    				return;
    			}
    		},paramUrl)
    	}
    	}); 
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 class="mui-title">综合操盘 - 支付确认</h1>		
		<a href="javascript:void(0);" class="top-tel" id="tran_info">操盘细则</a>
	</header>
	<!--<nav class="navlist">
		<a href="javascript:void(0);" id="product">
			<span class="mui-icon mui-icon-list"></span>
			<span class="mui-tab-label">产品</span>
		</a>
		<a class="navon" href="javascript:void(0);"  id="scheme">
			<span class="mui-icon mui-icon-compose"></span>
			<span class="mui-tab-label">方案</span>
		</a>
		<a    id="account" href="javascript:void(0);">
			<span class="mui-icon mui-icon-contact mui-icon-icon-contact-filled"></span>
			<span class="mui-tab-label" >账户</span>
		</a>
	</nav>-->
<div class="mui-content sc_listdeta pay_cp">	
	<h3 class="pay_title">操盘方案</h3>
	<ul class="mui-table-view sc_listac">
		<li class="mui-table-view-cell">
			<label>可交易品种：</label>
			<p id="tradelever_info"></p>
			<span class="pay_cpfont">注：以上手数为只交易该品种时，初始最大可持仓手数</span>
		</li>			
		<li class="mui-table-view-cell">
			<label>总操盘资金($)：</label>
			<span id="traderTotal">10,750美元</span>
		</li>		
		<li class="mui-table-view-cell">
			<label>亏损平仓线($)：</label>
			<span id="lineLoss">10,450美元</span>
		</li>
	</ul>
	<h3 class="pay_title">操盘费用</h3>
	<ul class="mui-table-view pay_list">
		<li class="mui-table-view-cell">
			<label>账户余额(¥)：</label>
			<span id="balance">10,750元</span>
			<p class="pay_money" id="pays_money" style="display: none;"><i class="mui-icon mui-icon-checkmarkempty"></i>余额充足</p>
			<p class="pay_nomoney" id="pays_nomoney" style="display: none;"><i class="mui-icon mui-icon-close-filled"></i>余额不足</p>
		</li>			
		<li class="mui-table-view-cell">
			<label>支付金额(¥)：</label>
			<span id="traderBond">10,450元</span>
			<b>操盘保证金</b>
		</li>		
	</ul>	
	<div class="ac_btn">
		<button class="mui-btn mui-btn-block pay_btn" type="button" style="display: none;"  id="payto">确认支付</button>	
		<button class="mui-btn mui-btn-block pay_btn" type="button" style="display: none;" id="chargeto">立即去充值</button>							
	</div>		
</div>
</body>
</html>